﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace testqwe
{
    class Trapezoid_stripe
    {
        //梯形条带
        //以底为准
        int diameter;
        double semidiameter;
        double bottomBase;
        double initlength;
        double marginlength;

        public int[,] u;
        public double[] width;
        public Trapezoid_stripe(double bottombase, int d)
        {
            diameter = d + Constant.Allowance;
            semidiameter = d / 2.0;
            bottomBase = bottombase;
            initlength = semidiameter * (Constant.SQRT_THREE + 1);
            marginlength = semidiameter * (2 * Constant.THIRD_OF_SQRT_THREE + 1);
            width = new double[Constant.ROW];
            u = new int[Constant.ROW, (int)bottombase + 1];
            initwid();
            initial();
        }

        //初始化 条带信息即条带中包含多少个毛坯
        private void initial()
        {
            for (int i = (int)initlength + 1; i < bottomBase; i++)
            {
                for (int j = 0; j < Constant.ROW; j++)
                {
                    int n=0;
                    double validlength = i - (semidiameter + Constant.SQRT_THREE * semidiameter * j) * Constant.THIRD_OF_SQRT_THREE;
                    if(validlength<marginlength) n=0;
                    else n = (int)((validlength - marginlength) / diameter) + 1;
                    if (j < 1)
                    {
                        u[j, i] = n;
                    }
                    else
                    {
                        u[j, i] = n + u[j - 1, i];
                    }  
                }
            }
            
        }
        
        //计算条带宽度
        private void initwid()
        {
            for (int t = 0; t < Constant.ROW; t++)
            {
                width[t] = diameter + t * diameter * Constant.SQRT_THREE / 2;
            }
        }
    }
}
